package com.github.wujichen158.andemusic.network;

import com.github.wujichen158.andemusic.eventsetting.MusicPlayer;
import com.github.wujichen158.andemusic.playernbt.MusicTypeProvider;
import net.minecraft.client.Minecraft;

import java.util.Optional;

public class ClientMsgHandler {
    public static void handleClientMsg(MusicMessage message) {
        Minecraft mc = Minecraft.getMinecraft();
        Optional.ofNullable(MusicTypeProvider.get(mc.player)).ifPresent(capability -> {
            mc.addScheduledTask(() -> {
                MusicPlayer.musicName = message.musicType;
                capability.setMusicType(message.musicType);
                MusicPlayer.EnhancedMusicTicker.minWait = message.minTime;
                MusicPlayer.EnhancedMusicTicker.maxWait = message.maxTime;
            });
        });
    }
}
